.global _start
.extern OSCtxSw
.extern armmain

.section vector
	NOP
	NOP
	b _OSCtxSw
	NOP
	NOP
	NOP
	b _OSTickISR
	NOP
	
_OSCtxSw:
    stmdb sp!, {r0-r12,r14}
    mrs r0, cpsr
    stmdb sp!,{r0}
    ldr r0,[sp,#60]
    ldr r1,[sp,#56]
    str r1,[sp,#60]
    str r0,[sp,#56]
    ldr r0,=OSCtxSw
    mov pc, r0

_OSTickISR:
    ldr sp, =temp_sp_top
    stmdb sp!, {r14}
    stmdb sp!, {r0-r12,r14}
    mrs r0, cpsr
    orr r0,r0,#0x13
    msr cpsr_c,r0

    ldr r1, =temp_sp_top
    mov r2, sp
    add r1,r1,#-4
    add r2,r2,#-4
    mov r3, #15
1:  
    ldr r4, [r1],#-4     @ 从Steppingstone读取4字节的数据，并让源地址加4
    str r4, [r2],#-4     @ 将此4字节的数据复制到SDRAM中，并让目地地址加4
    add r3,r3,#-1
    cmp r3, #0          @ 判断是否完成：源地址等于Steppingstone的未地址？
    bne 1b              @ 若没有复制完，继续
    
    add sp,sp,#-4
    stmdb sp!, {r14}
    add sp,sp,#-52
    mrs r0, cpsr
    stmdb sp!,{r0}
   
    
    ldr r0,=OSTickISR
    mov pc, r0
    
.text
_start:
    ldr r0, =0x60000000
    mcr p15,0,r0,c12,c0,0
    
    ldr sp, =sp_top
    bl armmain
    b .
    

